package com.pay.demo;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.pay.utils.FunctionUtils;

import cn.hutool.core.util.StrUtil;

/**
 * items.htm接口查询调用
 * @author Administrator
 *
 */
public class ItemsDemo {

	public static void main(String[] args) throws IOException {
		/*Document doc = Jsoup.connect("https://lab.alipay.com/consume/record/items.htm")
				.header("Cookie", "JSESSIONID=RZ190fcP5nDVAfSGEXJWjAnUTM2V8cauthRZ19GZ00; mobileSendTime=-1; credibleMobileSendTime=-1; ctuMobileSendTime=-1; riskMobileBankSendTime=-1; riskMobileAccoutSendTime=-1; riskMobileCreditSendTime=-1; riskCredibleMobileSendTime=-1; riskOriginalAccountMobileSendTime=-1; cna=S0AmFFnxgkkCAXkNxeE67GoM; UM_distinctid=1675b44c2e42f4-05e63f299f5b-4e7a4a11-13c680-1675b44c2e5532; 3FV_lastvisit=3%091544069326%09%2Findex.php%3Fm%3Du%26a%3Dshowcredit; isg=BG9vMrgSb-7tdmxtbqAeLkqG64O5vMN7Nb9g1YH8C17l0I_SieRThm0BVoDLqJuu; spanner=z+2ossAeEbNCMIPMOKpRNdsjThp5qWWNXt2T4qEYgj0=; CLUB_ALIPAY_COM=2088722153529552; iw.userid=\"K1iSL16QY1TOa0TWpNJUKg==\"; ali_apache_tracktmp=\"uid=2088722153529552\"; session.cookieNameId=ALIPAYJSESSIONID; unicard1.vm=\"K1iSL16QY1TOa0TWpNJUKg==\"; ctoken=0ZnE-yJaIfVZ1Y5G; LoginForm=alipay_login_home; alipay=\"K1iSL16QY1TOa0TWpNJUKpg336kutio3Se7lnfOBbQ==\"; zone=GZ00C; JSESSIONID=C8AEFC2DDDC86685B9DB4833B4AFC339; ALIPAYJSESSIONID=RZ190fcP5nDVAfSGEXJWjAnUTM2V8cauthRZ12GZ00; rtk=kTMUtUNAjQb4JS6QYTIGAYrFyzDM5G0FA16SgNNB2YXzoJm1gMH")
				.header("Origin", "https://lab.alipay.com")
				.header("Referer", "https://lab.alipay.com/consume/record/items.htm")
				.header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6788.400 QQBrowser/10.3.2727.400")
				.get();
		String title = doc.title();
		System.out.println(title);
		System.out.println();
		if(!"交易记录 - 支付宝".equals(title)) {
			return ; 
		}
		Element supper = doc.getElementById("supper");
		if(supper == null) {
			//警告
			return ; 
		}
		if(supper.text().indexOf("高级筛选") == -1) {
			return ;
		}
		Elements trElements = doc.select(".record-list");
		for (Element trElement : trElements) {
			String consumeBizNo = trElement.select(".number .consumeBizNo").text();
			String flagcode = trElement.select(".info .ft-gray").text();
			if(StrUtil.isBlank(flagcode)) {
				continue ;
			}
			String income = trElement.select(".income").text();
			if(StrUtil.isBlank(income)) {
				continue ;
			}
			System.out.println(FunctionUtils.getFlagcode(flagcode));
			System.out.println(consumeBizNo);
			System.out.println(income);
		}*/
		CloseableHttpClient httpClient=HttpClients.createDefault(); // 创建httpClient实例
		HttpGet httpget = new HttpGet("https://lab.alipay.com/consume/record/items.htm"); // 创建httpget实例
		httpget.addHeader("Cookie", "JSESSIONID=RZ19u88jOdoa9i46yn4XkJ7sexYgVdauthRZ24GZ00; mobileSendTime=-1; credibleMobileSendTime=-1; ctuMobileSendTime=-1; riskMobileBankSendTime=-1; riskMobileAccoutSendTime=-1; riskMobileCreditSendTime=-1; riskCredibleMobileSendTime=-1; riskOriginalAccountMobileSendTime=-1; cna=S0AmFFnxgkkCAXkNxeE67GoM; UM_distinctid=1675b44c2e42f4-05e63f299f5b-4e7a4a11-13c680-1675b44c2e5532; 3FV_lastvisit=3%091544069326%09%2Findex.php%3Fm%3Du%26a%3Dshowcredit; isg=BG9vMrgSb-7tdmxtbqAeLkqG64O5vMN7Nb9g1YH8C17l0I_SieRThm0BVoDLqJuu; CLUB_ALIPAY_COM=2088722153529552; iw.userid=\"K1iSL16QY1TOa0TWpNJUKg==\"; ali_apache_tracktmp=\"uid=2088722153529552\"; session.cookieNameId=ALIPAYJSESSIONID; unicard1.vm=\"K1iSL16QY1TOa0TWpNJUKg==\"; spanner=6PukVKHDlHFpraYdVqmOIOA3soyi4YDy4EJoL7C0n0A=; JSESSIONID=39AC18B40B91454E1D7EEF803BA277A4; LoginForm=alipay_login_auth; alipay=\"K1iSL16QY1TOa0TWpNJUKpg336kutio3Se7lnfOBbQ==\"; CNZZDATA1253107971=999202990-1543499760-https%253A%252F%252Fb.alipay.com%252F%7C1544444273; ctoken=rsZpgWqalS--n4Xo; ALIPAYJSESSIONID=RZ19UN0xYXtH5pWFo7nmkwxhv5D9IGauthRZ18GZ00; rtk=IWuZ4Cb2l1N6s84HvWkV2vys05VDPszq2e48KkbEAqtjPs0eKdQ; zone=GZ00C");
		httpget.addHeader("Origin", "https://lab.alipay.com");
		httpget.addHeader("Referer", "https://lab.alipay.com/consume/record/items.htm");
		httpget.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 QQBrowser/4.4.116.400 Version/5.1.1 Safari/534.51.22");
		CloseableHttpResponse response = httpClient.execute(httpget);
		HttpEntity entity=response.getEntity(); // 获取返回实体
		String result = EntityUtils.toString(entity, "utf-8");
		System.out.println(result);
		response.close(); 
		httpClient.close();
	}
}
